﻿Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web

Public Class Numero
  Inherits TextBox
  Implements IScriptControl

  Private EnterosValor As Integer = 8
  Private DecimalesValor As Integer = 2
  Private TipoValor As Tipos = Tipos.Fox
  Private RellenoValor As String = " "
  Private PermiteNegativosValor = True
  Dim ValidandoValor As String = ""
  Public Property Validando() As String
    Get
      Return ValidandoValor
    End Get
    Set(ByVal value As String)
      ValidandoValor = value
    End Set
  End Property

  Dim RangoDesdeValor As Decimal = Decimal.MinValue
  Public Property RangoDesde() As Decimal
    Get
      Return RangoDesdeValor
    End Get
    Set(ByVal value As Decimal)
      RangoDesdeValor = value
    End Set
  End Property
  Dim RangoHastaValor As Decimal = Decimal.MaxValue
  Public Property RangoHasta() As Decimal
    Get
      Return RangoHastaValor
    End Get
    Set(ByVal value As Decimal)
      RangoHastaValor = value
    End Set
  End Property

  Dim PermiteCeroValor As Boolean = True
  Public Property PermiteCero() As Boolean
    Get
      Return PermiteCeroValor
    End Get
    Set(ByVal value As Boolean)
      PermiteCeroValor = value
    End Set
  End Property

  Dim CssErrorValor As String = "Erroneo"
  Public Property CssError() As String
    Get
      Return CssErrorValor
    End Get
    Set(ByVal value As String)
      CssErrorValor = value
    End Set
  End Property


  Public Property Enteros() As Integer
    Get
      Return EnterosValor
    End Get
    Set(ByVal value As Integer)
      EnterosValor = value
    End Set
  End Property
  Public Property Decimales() As Integer
    Get
      Return DecimalesValor
    End Get
    Set(ByVal value As Integer)
      DecimalesValor = value
    End Set
  End Property
  Public Property Tipo() As Tipos
    Get
      Return TipoValor
    End Get
    Set(ByVal value As Tipos)
      TipoValor = value
    End Set
  End Property
  Public Property Relleno() As String
    Get
      Return RellenoValor
    End Get
    Set(ByVal value As String)
      RellenoValor = value
    End Set
  End Property
  Public Property PermiteNegativos() As Boolean
    Get
      Return PermiteNegativosValor
    End Get
    Set(ByVal value As Boolean)
      PermiteNegativosValor = value
    End Set
  End Property
  Enum Tipos
    Fox
    Calc
  End Enum

  Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
    If Not Me.DesignMode Then
      Dim SM As ScriptManager = ScriptManager.GetCurrent(Page)
      If SM Is Nothing Then
        Throw New HttpException("Debe existir un ScriptManager el la pagina")
      Else

        SM.RegisterScriptControl(Me)
      End If
    End If
    MyBase.OnPreRender(e)
  End Sub
  Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
    If Not Me.DesignMode Then
      ScriptManager.GetCurrent(Me.Page).RegisterScriptDescriptors(Me)
    End If
    MyBase.Render(writer)
  End Sub
  Public Function GetScriptDescriptors() As System.Collections.Generic.IEnumerable(Of System.Web.UI.ScriptDescriptor) Implements System.Web.UI.IScriptControl.GetScriptDescriptors
    Dim descriptor As New ScriptBehaviorDescriptor("MoniMisi2.Numero", Me.ClientID)
    Dim descriptors As New List(Of ScriptDescriptor)
    descriptor.AddProperty("Enteros", Me.Enteros)
    descriptor.AddProperty("Decimales", Me.Decimales)
    descriptor.AddProperty("Tipo", Me.Tipo.ToString)
    descriptor.AddProperty("Relleno", Me.Relleno)
    descriptor.AddProperty("PermiteNegativos", Me.PermiteNegativos)
    descriptor.AddProperty("RangoDesde", Me.RangoDesde)
    descriptor.AddProperty("RangoHasta", Me.RangoHasta)
    descriptor.AddProperty("CssError", Me.CssError)
    descriptor.AddProperty("PermiteCero", Me.PermiteCero)
    If Me.Validando <> String.Empty Then
      descriptor.AddEvent("Validando", Me.Validando)
    End If
    descriptors.Add(descriptor)
    Return descriptors
  End Function
  Public Function GetScriptReferences() As System.Collections.Generic.IEnumerable(Of System.Web.UI.ScriptReference) Implements System.Web.UI.IScriptControl.GetScriptReferences
    Dim scriptRef As New ScriptReference("MoniMisi2.Numero.js", Funciones.NombreCompletoEnsamblado(Me.GetType, "MoniMisi2.Numero"))
    Dim scriptRefs As New List(Of ScriptReference)
    scriptRef.NotifyScriptLoaded = False
    scriptRefs.Add(scriptRef)
    Return scriptRefs
  End Function
End Class


